package calendar;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Hashtable;

import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.multimedia.jolitorask.extension.calendar.util.timer.CalendarTimerLocal;
import org.multimedia.jolitorask.extension.calendar.util.timer.CalendarTimerLocalHome;


public class StartTimer extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static final String JNDI_NAME_TIMER = "calendarTimerSessionLocal";
	
	public StartTimer() {
		super();
	}   	
	
	@SuppressWarnings("unchecked")
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

	    res.setContentType("text/plain");
	    PrintWriter out = res.getWriter();
	    
	    	
	    try {
	    	
	    	InitialContext initContext = new javax.naming.InitialContext(new Hashtable(1));
	    	Object beanObject = initContext.lookup(JNDI_NAME_TIMER);

	    	CalendarTimerLocal c = ((CalendarTimerLocalHome)beanObject).create();
	    	c.startTimer();
	    	
	    	
	    }catch (Exception e) {
	    	out.println(false);
	    	e.printStackTrace();
	    	return;
		}

		out.println(true);
		
	    
	}
    
}
